<template>
  <Container class="storecheck-list">
    <HeadFormItem
      slot="header"
      :list="list"
      @onSearchBtnClick="onSearchBtnClick"
    />
    <Tabs v-model="tab">
      <TabPane label="签约门店审核列表" name="tab1">
        <homeTable
          :list="list"
          @getData="getData"
          @onPageSizeChange="onPageSizeChange"
          @onPageChange="onPageChange"
          @onSelectionChange="onSelectionChange"
        />
      </TabPane>
    </Tabs>
  </Container>
</template>
<script>
import SignCheckListData from './list/SignCheckListData'
import HeadFormItem from './list/HeadFormItem'
import homeTable from '@/components/homeTable'

import { clearEmpty } from '@/util'
export default {
  name: 'manage/storecheck/list',
  components: {
    HeadFormItem,
    homeTable
  },
  data () {
    return {
      tab: 'tab1',
      list: SignCheckListData,
      productIds: []
    }
  },
  watch: {
  },
  mounted () {
    this.getData()
    this.$bus.$on('checkRow', this.signEdit)
    this.$bus.$on('infoRow', this.signInfo)
  },
  destroyed () {
    this.$bus.$off()
  },
  methods: {
    onSearchBtnClick () {
      this.list.currentPage = 1
      this.getData()
    },
    signEdit (row) {
      this.$router.push({
        name: 'manage/storecheck/edit',
        query: {
          id: row.id,
          contractId: row.contractId
        }
      })
    },
    signInfo (row) {
      this.$router.push({
        name: 'manage/storecheck/info',
        query: {
          id: row.id,
          contractId: row.contractId
        }
      })
    },
    onChangeOwner () {
      this.$refs.supplerBind.openModal()
    },
    getData () {
      this.productIds = []
      this.list.status = 'loading'
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        ...this.list.form
      }
      param = clearEmpty(param)
      this.$jsonPost('/store_contract_audit/audit/page', param).then(data => {
        this.list.data = []
        this.list.totalItem = Number(data.total)
        this.list.data = (data.records || []).map(item => {
          let { applyOperator, applyTypeStr, id, auditStatus, auditStatusStr, contractId, storeTypeStr } = item.storeContractApplyDTO
          let { address, storeName, storeTypeName, ownerName, distributorName, signSourceStr, storeNo } = item.storeContractApplyDTO.applyDetailDTO || {}
          return { applyOperator, applyTypeStr, id, auditStatus, auditStatusStr, address, storeName, storeTypeName, ownerName, distributorName, canAudit: item.canAudit, signSourceStr, contractId, storeTypeStr, storeNo }
        })
        this.list.status = 'pass'
      }).catch(() => {
        this.list.status = 'error'
      })
    },
    onSelectionChange (selection) {
      this.productIds = (selection || []).map(item => item.id)
    },
    onPageChange (number) {
      this.list.currentPage = number
      this.getData()
    },
    onPageSizeChange (pageSize) {
      this.list.currentPage = 1
      this.list.pageSize = pageSize
      this.getData()
    },
    onRefresh () {
      this.getData()
    },
    onExport () {
      this.$Message.info('导出')
    }
  }
}
</script>
